package com.hw.service.impl;

import com.hw.dao.UserDao;
import com.hw.entity.User;
import com.hw.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;

/**
 * @author F1335240
 * @version 1.0
 * @date 2020/5/9 15:46
 **/
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao;

    @Override
    public void savaUser(User user) {
        BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
        String newPassword = bCryptPasswordEncoder.encode(user.getPassword());
        user.setPassword(newPassword);
        System.out.println("用户信息:" + user);
        userDao.insert(user);
    }

    @Override
    public User queryUserByUsername(String username) {
        return userDao.selectByUsername(username);
    }
}
